Sheffield | 26-ITP-Jan | Mahammad Osman | Sprint 2 | Data Groups#1131
Sheffield | 26-ITP-Jan | Mahammad Osman | Sprint 2 | Data Groups#1131Darkidd77 wants to merge 6 commits intoCodeYourFuture:mainfrom
Conversation
…ments for clarity
…ry-currency pairs
…s; implement tally function with error handling and corresponding tests
…omprehensive tests for various cases in invert.test.js. Create countWords function to count word occurrences in a string; add corresponding tests in count-words.test.js.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ing me to commit ann make my pr
| // Given invalid parameters like an array | ||
| // When passed to contains | ||
| // Then it should return false or throw an error | ||
| test("contains returns false for invalid parameters", () => { | ||
| const arr = [1, 2, 3]; | ||
| expect(contains(arr, "a")).toEqual(false); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
This test cannot not yet confirm that the function correctly returns false when the first argument is an array.
This is because contains([1, 2, 3], "a") could also return false simply because "a" is not a key of the array.
Arrays are objects, with their indices acting as keys. A proper test should use a valid
key to ensure the function returns false specifically because the input is an array, not because the key is missing.
In addition, does your function behave as expected when the first argument is null or undefined?
| const counts = {}; | ||
|
|
||
| for (const item of list) { | ||
| if (counts[item]) { | ||
| counts[item] = counts[item] + 1; | ||
| } else { | ||
| counts[item] = 1; | ||
| } | ||
| } |
There was a problem hiding this comment.
Does the following function call returns the value you expect?
tally(["toString", "toString"]);
Suggestion: Look up an approach to create an empty object with no inherited properties.
Learners, PR Template
Self checklist
Changelist:
Completed the tasks per instructions.